/*
 * Created on 04/05/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.drivers;

import br.ufmg.dees.insane.util.IVector;
import br.ufmg.dees.insane.util.LinearEquationSystems;
import br.ufmg.dees.insane.util.SingularMatrixException;

/**
 * @author jamile
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StaticLinear implements Solution{
	LinearEquationSystems sel = new LinearEquationSystems();
	StructuralMech driver;
	
	public StaticLinear(StructuralMech dv){
		this.driver = dv;
	}
		public void execute() throws SingularMatrixException
		{
			try 
			{
				driver.init();
				if (driver.getNumberOfEquations()!=0) 
				{
					sel.setAMatrix(driver.reducedStiffnessMatrix());
					sel.setBVector(driver.reducedNodalForceVector());
					sel.addToBVector(driver.reducedEquivalentForceVector());
					sel.addToBVector(driver.reducedPreDisplacementEquivalentForceVector());
					sel.solverX();
					driver.assignKinematicState(sel.getXVector());
				}
				else
				{
					sel.setBVector(new IVector(driver.getNumberOfRestraints()));
				}
				
				sel.setAMatrix(driver.reactionsStiffnessMatrix());
				sel.setXVector(driver.reducedDisplacementVector());
				sel.solverB();
				sel.subFromBVector(driver.reactionsEquivalentForceVector());
				sel.addToBVector(driver.reactionsPreDisplacementEquivalentForceVector());
				sel.subFromBVector(driver.reactionsNodalForceVector());
				driver.assignStaticState(sel.getBVector());
//				driver.calculateInternalForces();
				driver.addPrescribedDisplacements();
				
			} 
			catch (SingularMatrixException e)
			{
				throw (e);
			} 
			catch (Exception e1)
			{
				System.out.println("An exception occured during model analysis.");
				System.out.println(e1.getClass());
			}
		}
	
	public void setStep(Step sp){
		
	}
}
